// pages/Account/Account.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data:{},//信息平台
    tel:'',//店铺手机号
    hasUserInfo: false,
    hasLogin: wx.getStorageSync("token") ? true : false,
    showSetting: false,
  },
  // 获取用户信息
  getUserInfo(res) {
    console.log(res.detail.userInfo)
    let that = this;
    wx.setStorageSync("userName", res.detail.rawData);
    var userName = res.detail.userInfo;
    if (res.detail.userInfo) {
      wx.login({
        success: function (res) {
          let code = res.code;
          console.log(code)
          app.post("/login/check", "post", {}).then(data => {
            if (data.statusCode == "302") {
              wx.navigateTo({
                url: '/pages/login/login?code=' + code + "&nickName=" + userName.nickName + "&avatarUrl=" + userName.avatarUrl
              })
            } else {
              wx.setStorageSync("token", data.token);
              that.setData({ hasLogin: true });
              wx.showToast({
                title: '登录成功'
              })
            }
          }, err => {
            console.log(err)
          })



        }
      })

    } else {

      wx.showToast({ title: '请再次点击授权允许', icon: 'none', duration: 1500 })
      that.setData({ showSetting: true })
    }
  },
  //设置回调
  settingBack: function (res) {
    let that = this;
    if (res.detail.authSetting['scope.userLocation']) {
      that.setData({ showSetting: false });
      that.location();
    }
    if (res.detail.authSetting['scope.userInfo']) {
      that.setData({ showSetting: false });
    }
  },
  sginClick(){
    let that = this;
    wx.showModal({
      title: '提示',
      content: '您确认要注销账户吗？',
      success:function(res){
        if (res.cancel) {

        }else{
          wx.removeStorage({
            key: 'token'
          });
          that.setData({ hasLogin:false})
        }
      }
    })
  },
  // 完成实名
  Finished:function(e){
    // console.log(e)
    var id = e.currentTarget.id;
    wx.navigateTo({
      url: '../certification/certification?id='+id,
    })
  },
  ModifyPWD: function () {
    let that = this;
    wx.navigateTo({
      url: '../modify/modify?tel='+that.data.tel,
    })
  },
  myMessage: function () {
    wx.navigateTo({
      url: '../myMessage/myMessage',
    })
  },
  about: function () {
    wx.navigateTo({
      url: '../about/about',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    app.post("/personal/info","get",{}).then(res =>{
      console.log(res)
      that.setData({ data: res, tel: res.merchant_account})
    })
    
    that.setData({ hasLogin: wx.getStorageSync("token") ? true : false });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})